package com.steven.sync;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * atomic线程安全的不会出现错加和错减的情况
 */
public class AtomicInteger_test {

     private  static  AtomicInteger atomicInteger = new AtomicInteger(0);


    public static void main(String[] args) {
        new Thread(()->{
            for (int i = 0; i < 10; i++) {
                atomicInteger.incrementAndGet();
                System.out.println(atomicInteger);
            }
        }).start();
        new Thread(()->{
            for (int i = 0; i < 10; i++) {
                atomicInteger.incrementAndGet();
                System.out.println(atomicInteger);
            }
        }).start();


    }

}
